export default {
	data () {
		return {
			search_query: {
				page: 1,
				size: 10,
				type: 'short',
				need_page: 1,
				name: ""
			},
			labels: '',
			total: 0,
			search_labels: [],
		}
	},
	methods: {
		searchLabel (page = 1, name = '',cb=null) {
			this.search_query.page = page
			if (name != '') {
				this.search_query.name = name
			}
			this.$request.get("/labels/index", this.search_query).then((res) => {
				if (page == 1) {
					this.search_labels = res.items
				} else {
					this.search_labels = this.search_labels.concat(res.items)
				}
				if(cb){
					cb(this.search_labels)
				}
				this.total = res.page.total
			})
		},
		nextPageLabel () {
			this.search_query.page++

			this.searchLabel(this.search_query.page)
		},
		loadSearch (value) {
			if (!value) {
				return this.resetSearch()
			}
			this.searchLabel(1, this.labels)
		},
		querySearch (queryString, cb) {
			if (queryString) {
				this.searchLabel(1, queryString,cb)
				
			} else {
				this.search_labels = []
				cb(this.search_labels);
			}

		},
		
	}
}